package com.shopping.utils;

import lombok.experimental.UtilityClass;
import org.apache.commons.codec.digest.DigestUtils;

@UtilityClass
public class MD5Utils {

    /**
     * md5加密
     * @param src
     * @return
     */
    public String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    private final String salt="1a2b3c4d";

    public String inputPassFormPass(String pass){
        String s = ""+salt.charAt(0) + salt.charAt(3) + pass + salt.charAt(4) + salt.charAt(5);
        return md5(s);
    }

    public String fromPassInputPass(String pass,String salt){
        String s = ""+salt.charAt(0) + salt.charAt(3) + pass + salt.charAt(4) + salt.charAt(5);
        return md5(s);
    }

    public String inputPassToDB(String pass,String salt){
        //用户层第一次加密
        String fromPass = inputPassFormPass(pass);
        //第二次加密
        String dbPass = fromPassInputPass(fromPass, salt);
        return dbPass;

    }

    public static void main(String[] args) {
        System.out.println(inputPassFormPass("123456"));//29e49ef25a71257056231f00771877b8
        System.out.println(fromPassInputPass(inputPassFormPass("123456"), "1a2b3c4d"));//5be427c9edbfc15800e90c54b0a5a809
        System.out.println(inputPassToDB("123456", "1a2b3c4d"));//5be427c9edbfc15800e90c54b0a5a809
    }

}
